package com.his.his_system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.his.his_system.common.util.ResultAdvice;
import com.his.his_system.domain.DzmHisRegisteredfee;
import com.his.his_system.domain.DzmHisRegisteredfeeSub;
import com.his.his_system.service.DzmHisRegisteredfeeService;
import com.his.his_system.service.DzmHisRegisteredfeeSubService;
import com.his.his_system.vo.RegisteredfeeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/his/sys/regf/")
@RestController
@ResponseBody
public class RegisteredfeeController {

    @Autowired
    private DzmHisRegisteredfeeService service;

    @Autowired
    private DzmHisRegisteredfeeSubService subservice;




    /**
     * 查询全部
     * @return
     */
    @GetMapping("/list")
    public ResultAdvice list() {
        return ResultAdvice.success(service.list());
    }


    /**
     * 查询单个
     * @return
     */
    @GetMapping("/get/{regId}")
    public ResultAdvice get(@PathVariable("regId") Integer regId) {
        return ResultAdvice.success(service.getById(regId));
    }

    /**
     * 子表查询全部
     * @return
     */
    @GetMapping("/list_sub")
    public ResultAdvice listSub(Integer regId) {
        QueryWrapper<DzmHisRegisteredfeeSub> qr = new QueryWrapper<DzmHisRegisteredfeeSub>().eq("reg_id", regId);
        return ResultAdvice.success(subservice.list(qr));
    }

    /**
     * 模糊查询
     * @param
     * @return
     */
    @GetMapping("/like")
    public ResultAdvice like(String keyWord) {
        QueryWrapper<DzmHisRegisteredfee> qr =
                new QueryWrapper<DzmHisRegisteredfee>().like("registeredfee_name", keyWord);
        return ResultAdvice.success(service.list(qr));
    }

    /**
     * 添加
     * @param registeredfee
     * @return
     */
    @PostMapping("/add")
    public ResultAdvice add(@RequestBody RegisteredfeeVo registeredfee) {

        return ResultAdvice.success(service.saveOne(registeredfee,subservice));
    }

    @PostMapping("/modify")
    public ResultAdvice modify(@RequestBody RegisteredfeeVo regvo){
        return ResultAdvice.success(service.modify(regvo,subservice));
    }
    @PostMapping("/del/{id}")
    public ResultAdvice del(@PathVariable("id") Integer regId){
        return ResultAdvice.success(service.removeGroup(regId,subservice));
    }

}
